<?php

/**
 * @name ErrorController
 * @desc 错误控制器, 在发生未捕获的异常时刻被调用
 * @see http://www.php.net/manual/en/yaf-dispatcher.catchexception.php
 * @author root
 */
class ErrorController extends \Yaf\Controller_Abstract
{
    /**
     * @param $exception Yaf\Exception
     */
    public function errorAction($exception)
    {
        // assign to view engine
        assert($exception);
        $view_ = $this->getView();
        $view_->setScriptPath(APP_PATH . '/views');
        switch ($exception->getCode()) {
            case YAF\ERR\NOTFOUND\MODULE:
            case YAF\ERR\NOTFOUND\CONTROLLER:
            case YAF\ERR\NOTFOUND\ACTION:
            case YAF\ERR\DISPATCH\FAILED:
            case YAF\ERR\ROUTE\FAILED :
            //404
                header("Not Found");
                $view_->display('error/404.html');
                break;
            case YAF\ERR\AUTOLOAD\FAILED :
            case YAF\ERR\NOTFOUND\VIEW :
            case YAF\ERR\STARTUP\FAILED  :
            case YAF\ERR\TYPE\ERROR   :
            case YAF\ERR\CALL\FAILED    :

            case 500:
                //自定义的异常
                break;
            default:
                $view_->display('error');
        }


        $view_->assign("code", $exception->getCode());
        $view_->assign("message", $exception->getMessage());
        $view_->assign("line", $exception->getLine());
        $view_->assign("file", $exception->getFile());
    }

}